//package com.handydata.antifraud.rule;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.handydata.AntifraudInsApplication;
//import com.handydata.antifraud.bo.orderbaseinfo.OrderBaseInfoReqBO;
//import com.handydata.antifraud.to.RiskInputTO;
//import com.handydata.antifraud.to.TO;
//import com.handydata.antifraud.to.RiskOutputTO;
//import com.handydata.antifraud.vo.orderbaseinfo.CreateOrderBaseInfoReqVO;
//import com.handydata.common.convert.CommonBeanConvertor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.io.FileUtils;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.*;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import java.io.File;
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Field;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//
//@Slf4j
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes = AntifraudInsApplication.class)
//public class RuleInvokerTestEquipRel {
//
//    @Test
//    public void test() {
//        RuleEngineInvoker ruleEngineInvoker = new RuleEngineInvoker("anti-fraud/ws_equip_rel_package", "devRelExDecision");
//
//        try{
//           String str= FileUtils.readFileToString(new File("/Users/baiyx/Desktop/testdata/20190909110121SHYH000000009.json"));
//            Map<String, Object> clearTextMap = JSONObject.parseObject(str);
//            //推送数据参数校验
//            CreateOrderBaseInfoReqVO createOrderBaseInfoReqVO = CommonBeanConvertor.convert(clearTextMap, CreateOrderBaseInfoReqVO.class);
//            createOrderBaseInfoReqVO.setRecieveData(JSONObject.toJSONString(clearTextMap.get("logicData")));
//
//            OrderBaseInfoReqBO orderBaseInfoReqBO = CommonBeanConvertor.convert(createOrderBaseInfoReqVO, OrderBaseInfoReqBO.class);
//
//            JSONObject receiveData = JSON.parseObject(orderBaseInfoReqBO.getRecieveData());
//
//            preDealData(receiveData);
//
//            RiskInputTO riskInputTO = copyProperties(receiveData, RiskInputTO.class);
//
//            RiskMiddleTO riskMiddleTO = new RiskMiddleTO();
//            RiskOutputTO riskOutputTO = new RiskOutputTO();
//            ruleEngineInvoker.invokeDecision(session -> {
//                session.insert(riskInputTO);
//                session.insert(riskMiddleTO);
//                session.insert(riskOutputTO);
//            });
//
//            Field[] fs= riskMiddleTO.getClass().getDeclaredFields();
//            for(Field f :fs){
//               Annotation[] as= f.getDeclaredAnnotations();
//               if(as[0].toString().indexOf("APP")!=-1){
//                   //System.out.println(as[0].toString()+":"+ f.getInt(riskMiddleTO));
//                   System.out.println(as[0].toString()+org.apache.commons.beanutils.BeanUtils.getProperty(riskMiddleTO,f.getName()));
//               }
//            }
//
//            System.out.println(JSON.toJSON(riskOutputTO).toString());
//
//           // System.out.println(JSON.toJSON(riskMiddleTO).toString());
//           // assertThat(riskInputTO.getPhoneCity()).isNotEmpty().isEqualTo("四川,成都");
//
//        }catch (Exception ex){
//            ex.printStackTrace();
//        }
//
//
//    }
//    private void preDealData(JSONObject receiveData){
//        String appList=receiveData.getString("appList");
//        if(appList!=null&&appList.startsWith("[")&&appList.endsWith("]")){
//            List list=new ArrayList();
//            String[] strs=appList.replace("[","").
//            replace("]","").split(",");
//            receiveData.put("appList",new ArrayList<>(Arrays.asList(strs)));
//        }
//        String totalMemoryCapacity=receiveData.getString("totalMemoryCapacity");
//        if(totalMemoryCapacity!=null&&totalMemoryCapacity.length()>0){
//
//            totalMemoryCapacity= totalMemoryCapacity.replace("M","");
//            if(totalMemoryCapacity.indexOf("GB")!=-1){
//                receiveData.put("totalMemoryCapacity",getDouble(totalMemoryCapacity.replace("GB",""))*1024);
//            }else {
//                receiveData.put("totalMemoryCapacity",getDouble(totalMemoryCapacity));
//            }
//        }
//        String sdCardCapacity=receiveData.getString("sdCardCapacity");
//        if(sdCardCapacity!=null&&sdCardCapacity.length()>0){
//            sdCardCapacity= sdCardCapacity.replace("M","");
//            if(sdCardCapacity.indexOf("GB")!=-1){
//                receiveData.put("sdCardCapacity",getDouble(sdCardCapacity.replace("GB",""))*1024);
//            }else {
//                receiveData.put("sdCardCapacity",getDouble(sdCardCapacity));
//            }
//        }
//        String dumpEnergy=receiveData.getString("dumpEnergy");
//        if(dumpEnergy!=null&&dumpEnergy.length()>0){
//            receiveData.put("dumpEnergy",getDouble(dumpEnergy.replace("mah","")));
//        }
//        String batteryCapacity=receiveData.getString("batteryCapacity");
//        if(dumpEnergy!=null&&dumpEnergy.length()>0){
//            receiveData.put("batteryCapacity",getDouble(batteryCapacity.replace("mah","")));
//        }
//        String mobileCapacity=receiveData.getString("mobileCapacity");
//        if(mobileCapacity!=null&&mobileCapacity.length()>0){
//            receiveData.put("mobileCapacity",getDouble(mobileCapacity.replace("G","")));
//        }
//
//    }
//    private double getDouble(String val){
//        if(val==null)
//            return 0D;
//        try {
//            return  Double.valueOf(val);
//        }catch (Exception ex){
//            ex.printStackTrace();
//        }
//        return  0D;
//    }
//    private <T> T copyProperties(Map<String, Object> map, Class<T> cls) {
//        T obj = (T) BeanUtils.instantiateClass(cls);
//        BeanWrapper beanWrapper = new BeanWrapperImpl(obj);
//        beanWrapper.setPropertyValues((PropertyValues)(new MutablePropertyValues(map)),true,true);
//        return obj;
//    }
//}
